#ifndef __WIN_STUFF_H__
#define __WIN_STUFF_H__

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "iperf.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef __int64 int64_t;
typedef LONG_PTR ssize_t, *pssize_t;

#define snprintf _snprintf

#ifndef _TIMESPEC_DEFINED
#define _TIMESPEC_DEFINED       1
    struct timespec
    {
        time_t  tv_sec;         /* seconds */
        long    tv_nsec;        /* nano seconds */
    };
#endif 

#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
#else
  #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
#endif
 
struct timezone 
{
  int  tz_minuteswest; /* minutes W of Greenwich */
  int  tz_dsttime;     /* type of dst correction */
};

int getTempFileName(char *outbuffer, int maxchar);
int nanosleep(const struct timespec *request, struct timespec *remain);
int gettimeofday(struct timeval *tv, struct timezone *tz);
int get_tcpmaxseg(int s);

// GET OPT STUFF -> from NetBSD Lic. see source 'win_getopt.c' for license details
#define REPLACE_GETOPT
#ifdef _WIN32
# define __P(args)      args
#endif


/*
 * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
 */
#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#define no_argument        0
#define required_argument  1
#define optional_argument  2

struct option {
        /* name of long option */
        const char *name;
        /*
         * one of no_argument, required_argument, and optional_argument:
         * whether option takes an argument
         */
        int has_arg;
        /* if not NULL, set *flag to val when option found */
        int *flag;
        /* if flag not NULL, value to set *flag to; else return value */
        int val;
};

int getopt_long __P((int, char * const *, const char *, const struct option *, int *));
#endif

#ifdef _WIN32
/* These are global getopt variables */

extern int   opterr,   /* if error message should be printed */
                        optind,   /* index into parent argv vector */
                        optopt,   /* character checked for validity */
                        optreset; /* reset getopt */
extern char* optarg;   /* argument associated with option */

/* Original getopt */
int getopt __P((int, char * const *, const char *));
#endif





#ifdef __cplusplus
}
#endif
#endif
